﻿common_guide_model =
{
    --[[uin = 0;
    common_guide_local_cfg_key = "cloud_gaming.entry_new_guide";
    server_record_item = "31";
    server_record_sub_item = "CloudGameNewGuide";
    guide_has_shown = nil;

    cur_focus_game_id = nil;
    show_entry_game_id = nil;]]--
};

function common_guide_model:new (game_id, local_cfg_key, record_item, record_sub_item,
        guide_url, guide_report_type, use_server_record, need_cloudgame_permission, need_game_permission)
    local key = "control_" ..tostring(game_id) .. "_local_key_" .. tostring(local_cfg_key) .."_item_"
                        .. tostring(record_item) .. "_sub_item_" ..tostring(record_sub_item);
    local o = {show_entry_game_id = game_id, common_guide_local_cfg_key = local_cfg_key,
    server_record_item = record_item, server_record_sub_item = record_sub_item,
    guide_has_shown = nil, uin = 0,guide_url_ = guide_url, guide_report_type_ = guide_report_type,
    cur_focus_game_id = 0, key_ = key, use_server_record_ = use_server_record,
    need_cloudgame_permission_ = need_cloudgame_permission,
    need_game_permission_ = need_game_permission,
    get_cloud_game_permission_ = false, get_game_permission_ = false};
    setmetatable(o, self);
    self.__index = self;
    o:init(local_cfg_key, record_item, record_sub_item, need_cloudgame_permission, need_game_permission);
    return o;
end;

function common_guide_model:init(local_cfg_key, record_item, record_sub_item,
           need_cloudgame_permission, need_game_permission)
    self.common_guide_local_cfg_key = local_cfg_key;
    self.server_record_item = record_item;
    self.server_record_sub_item = record_sub_item;
    self.need_cloudgame_permission = need_cloudgame_permission;
    self.need_game_permission = need_game_permission;
    self:inner_log("local_cfg_key:" ..tostring(local_cfg_key)
        .. ",record_item:" .. tostring(record_item)
        .. ",record_sub_item:" .. tostring(record_sub_item)
        .. ",need_cloudgame_permission:" .. tostring(need_cloudgame_permission)
        .. ",need_game_permission:" .. tostring(need_game_permission), true);
end;

function common_guide_model:inner_log (msg, core_msg)
    base_utility.log(string.format("[common_guide_model] %s", msg), core_msg);
end;

function common_guide_model:get_local_common_guide_cfg()
    local data = {};
    data["common"] = 0;
    data["key"] = self.common_guide_local_cfg_key;
    local config = comm_center.call_service("Svr_GetConfig", data);
    return config;
end;

function common_guide_model:set_local_common_guide_cfg()
    local data = {};
    data["common"] = 0;
    data["key"] = self.common_guide_local_cfg_key;
    local config_tb = {};
    config_tb["is_show"] = "1";
    data["value"] = base_utility.table_to_json(config_tb);
    comm_center.call_service("Svr_SetConfig", data);
end;

function common_guide_model:set_server_common_guide_cfg()
    self.inner_log("set_server_common_guide_cfg");
    base_utility.set_accumulate_count(self.server_record_item,
            self.server_record_sub_item, 1, tostring(self.uin), 
            "common_guide_control_mgr.on_set_server_common_guide_cfg", self.key_);
    self:set_local_common_guide_cfg();
end;

function common_guide_model:on_set_server_common_guide_cfg(json_str)
    self:inner_log("on_set_server_common_guide_cfg : "..json_str);
    local result_tb = base_utility.json_to_table(json_str);
    if nil == result_tb then
        return;
    end

    if 0 == result_tb.result then
        self:inner_log("set server success");
    end
end;